import React from 'react'
import PubSub from 'pubsub-js'
import axios from 'axios'
import './Header.css'
class Header extends React.Component {
    searchTest = React.createRef()
    search = () => {
        const {current:{value:keyWord}} = this.searchTest
        // this.props.saveUsers({isFirst:false,isLoading: true})
        PubSub.publish('subtxt',{isFirst:false,isLoading: true})
        console.log(5555)
        axios.get(`/api1/search/users?q=${keyWord}`).then(response => {
            // console.log("请求成功！",response.data.items)
            // this.props.saveUsers({isLoading: false,users: response.data.items})
            PubSub.publish('subtxt',{isLoading: false,users: response.data.items})
        }).catch(error => {
            console.log("请求失败！",error)
            // this.props.saveUsers({isLoading: false,err:error.message})
            PubSub.publish('subtxt',{isLoading: false,err:error.message})
        })
    }
    render() {
        return (
            <section className="jumbotron">
                <h3 className="jumbotron-heading">搜索github用户</h3>
                <div>
                    <input ref={this.searchTest} type="text" placeholder="请输入内容" />&nbsp;
                    <button onClick={this.search}>搜索</button>
                </div>
            </section>
        )
    }
}

export default Header